package cn.t.enums.user;


import cn.t.core.enums.base.CommonEnum;
import cn.t.core.exception.BaseError;
import cn.t.core.exception.BizException;
import cn.t.core.enums.base.CommonError;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum UserError implements BaseError, CommonEnum<Integer, String> {

    PASSPORT_IS_NOT_EXISTS(100001, "通行证不存在"),
    GENERATE_VALIDATE_CODE_TOO_FAST(100002, "验证码刷新频繁，请稍后再试！"),
    VALIDATE_CODE_FAILED(100003, "验证码验证失败。"),
    VALIDATE_PASSWORD_FAILED(100004, "用户密码验证失败。"),
    PASSPORT_IS_NOT_AVAILABLE(200001, "通行证不可用"),
    DUPLICATED_PASSPORT(200002, "重复的通行证"),
    PERMISSION_DENIED(200003, "无访问权限");;

    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;

    public static UserError getByCode(Integer source) {
        for (UserError value : UserError.values()) {
            if (value.code.equals(source)) {
                return value;
            }
        }

        throw new BizException(CommonError.ILLEGAL_PARAMETER);
    }


}
